<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<head th:replace="/common/include :: header(~{::title}, ~{::link}, ~{::style})">
    <title>DEMO-弹窗-表格弹层-Check</title>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="selectUser()">
                <i class="fa fa-check"></i> 选择
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<div th:replace="/common/include :: footer"></div>

<script th:inline="javascript">

    var layer_index = [[${layer_index}]];
    var layer_callback = [[${layer_callback}]];
    var status_data_list = [[${@dict.getDataGroup('sys_normal_disable')}]];

    $(function () {
        var options = {
            code: 'userId',
            url: ctx + 'api/system/user/table',
            sortName: 'createTime',
            sortOrder: 'asc',
            search: false,
            showExport: false,
            pagination: true,
            queryParams: function(params) {
                return {
                    // 传递参数查询参数
                    limit:     params.limit,
                    offset:    params.offset,
                    search:    params.search,
                    sort:      params.sort,
                    order:     params.order,
                    Q_status_S_EQ: '0'
                };
            },
            columns: [{
                checkbox: true
            },
                {
                    field: 'loginName',
                    title: '登录名称',
                    sortable: true
                },
                {
                    field: 'userName',
                    title: '用户名称'
                },
                {
                    field: 'avatar',
                    title: '头像',
                    sortable: false,
                    formatter: function(value, row, index) {
                        $.table.imageView(value, row, index);
                    }
                },
                {
                    field: 'deptName',
                    title: '部门'
                },
                {
                    field: 'email',
                    title: '邮箱',
                    visible: false
                },
                {
                    field: 'mobile',
                    title: '手机'
                },
                {
                    field: 'status',
                    title: '状态',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.common.dictLabel(status_data_list, value);
                    }
                },
                {
                    field: 'loginTime',
                    title: '登陆时间',
                    sortable: true
                }]
        };

        $.table.init('bootstrap-table', options);
    });

    function selectUser() {
        var userIds = $.table.getSelectCode('loginName');

        // 回调函数
        if (layer_index && layer_callback) {
            var frameIndex = $.common.iframe.get(layer_index);
            if(window.execScript) {
                // 给IE的特殊待遇
                var fn = frameIndex.window.execScript(layer_callback);
                fn.call(this, userIds);
            } else {
                // 给其他大部分浏览器用的
                var fn = frameIndex.window.eval(layer_callback);
                fn.call(this, userIds);
            }
        }
        // 关闭当前窗口
        closeWin();
    }

    function closeWin() {
        $.modal.lay.close();
    }

</script>
</body>
</html>
